﻿using System;

namespace 第二次课作业
{
    class 作业
    {
        static void Main(string[] args)
        {
            //字符统计
            //数组统计和平均值
            //数组排序的方法
            //找数组元
            // 九九乘法表
            //打印空心正方形
            //打印菱形
            //打印实心正方形
            //打印杨辉三角!!!
            //数组排序下标偶数
            //数组排序
            
            Console.Read();

        }
        static void 字符统计(string[] args)
        {
            int Letter = 0;
            int Digit = 0;
            int Space = 0;
            Console.WriteLine("请输入一串字符：");
            String a = Console.ReadLine();
            foreach (var item in a)
            {
                if (char.IsLetter(item)) { Letter += 1; }
                else if (char.IsDigit(item)) { Digit += 1; }
                else if (char.IsWhiteSpace(item)) { Space += 1; }

            }
            Console.WriteLine("字符数：" + Letter);
            Console.WriteLine("数字数：" + Digit);
            Console.WriteLine("空格数：" + Space);
        }

        static void 数组统计和平均值(string[] args)
        {
            Console.WriteLine("语文     " + "数学     " + "英语     ");
            double sum = 0;
            double[,] arr = new double[5, 3] { { 100, 100, 100 }, { 23, 34, 100 }, { 75, 75, 85 }, { 74, 72, 89 }, { 89, 98, 67 } };
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                Console.WriteLine("");
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j] + "     ");
                }
            }
            foreach (double zf in arr)
            {
                sum += zf;

            }
            Console.WriteLine("");
            Console.WriteLine("总分为：" + sum);
            Console.WriteLine("平均分为：" + sum / 5);
        }
        static void 数组排序的方法(string[] args)
        {
            int[] arr = new int[5];
            arr[0] = 1234;
            arr[1] = 432;
            arr[2] = 4325;
            arr[3] = 13454;
            arr[4] = 4245;
            Console.WriteLine("排序前");
            Console.WriteLine("");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " .");

            }
            for (int j = 0; j < 10; j++)
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    if (i < 4)
                    {
                        if (arr[i] < arr[i + 1])
                        {
                            (arr[i], arr[i + 1]) = (arr[i + 1], arr[i]);
                        }
                    }
                }
            }
            Console.WriteLine("");
            Console.WriteLine("排序后");
            Console.WriteLine("");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " .");

            }
        }
        static void 找数组元素(string[] args)
        {
            int x = 0;
            int[] arr = new int[] { 1223, 123, 423, 534, 6765, 2341, 5342, 45 };
            Console.WriteLine("数组列表:");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " ");
            }
            Console.WriteLine("");
            Console.WriteLine("请输入要查找的数字：");
            x = int.Parse(Console.ReadLine());
            for (int i = arr.Length - 1; i >= 0; i--)
            {
                if (x == arr[i]) { Console.WriteLine("该数字出现在数组中的第" + (i + 1) + "位"); break; }
                else if (x != arr[i] && i == 0) { Console.WriteLine("找不到该数字"); }
            }
        }
        static void 九九乘法表(string[] args)
        {
            Console.WriteLine("这是一个九九乘法表");
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j < 10; j++)
                {
                    if (j <= i)
                    {
                        if (j == i) { Console.WriteLine(i + "*" + j + "=" + i * j); }
                        else { Console.Write(i + "*" + j + "=" + i * j + " "); }
                    }
                }
            }


        }
        static void 打印空心正方形(string[] args)
        {
            int a = 0;
            Console.WriteLine("请输入正方形的边长");
            String x = Console.ReadLine();
            a = int.Parse(x);
            for (int i = 1; i <= a; i++)
            {
                for (int j = 1; j <= a; j++)
                {
                    if (i == 1 || i == a)
                    {
                        if (j == a) { Console.WriteLine("*"); }
                        else { Console.Write("* "); }
                    }
                    else
                    {
                        if (j == 1) { Console.Write("* "); } else if (j == a) { Console.WriteLine("*"); } else { Console.Write("  "); }
                    }
                }
            }
        }
        static void 打印菱形(String[] args)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (j >= 4 - i && j <= 4 + i) { Console.Write("* "); }
                    else if (j == 8) { Console.WriteLine("  "); }
                    else { Console.Write("  "); }
                }
            }
            Console.WriteLine("");
            for (int i = 4; i >= 0; i--)
            {
                for (int j = 8; j >= 0; j--)
                {
                    if (j >= 5 - i && j <= i + 3) { Console.Write("* "); }
                    else if (j == 0) { Console.WriteLine(" "); }
                    else { Console.Write("  "); }
                }
            }
        }
        static void 打印实心正方形(string[] args)
        {
            int a = 0;
            Console.WriteLine("请输入实心正方形的边长：");
            String x = Console.ReadLine();
            a = int.Parse(x);
            for (int i = 1; i <= a; i++)
            {
                for (int j = 1; j <= a; j++)
                {
                    if (j == a) { Console.WriteLine("*"); }
                    else { Console.Write("* "); }
                }
            }
        }
        static void 打印杨辉三角(string[] args)
        {
            int[] arr = new int[23];
            for (int i = 1; i < 11; i++)
            {
                for (int j = 1; j < 22; j++)
                {
                    if (i % 2 == 1)
                    {
                        if (j == 10 + i || j == 12 - i)
                        {
                            arr[j] = 1;
                            if (j == 12 - i)
                            {
                                Console.Write(" " + arr[j]);
                            }
                            else if (j == 10 + i) { Console.Write(arr[j]); }
                        }
                        else if (j < 10 + i && j > 12 - i && j % 2 == 1)
                        {
                            arr[j] = arr[j - 1] + arr[j + 1];
                            Console.Write(arr[j]);
                        }

                    }
                    else if (j == 21) { Console.WriteLine(""); }
                    else { Console.Write(" "); }

                    if (i % 2 == 0)
                    {
                        if (j == 10 + i || j == 12 - i)
                        {
                            arr[j] = 1;
                            Console.Write(arr[j]);
                        }
                        else if (j < 10 + i && j > 12 - i && j % 2 == 0)
                        {
                            arr[j] = arr[j - 1] + arr[j + 1];
                            Console.Write(arr[j]);
                        }

                    }
                    else if (j == 21) { Console.WriteLine(""); }
                    else { Console.Write(" "); }
                }
            }
        }
        static void 数组排序下标偶数(string[] args)
        {
            String[] arr = new string[] { "老人与海", "红拂夜奔", "一只特立独行的猪", "阿Q正传", "淘气包马小跳" };
            Console.WriteLine("原数组");
            Console.WriteLine("                               ");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }
            Console.WriteLine("****************************");
            Console.WriteLine("下标为偶数的：");
            Console.WriteLine("                               ");
            for (int i = 0; i < arr.Length; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine(arr[i]);
                }
            }

        }
        static void 数组排序(string[] args)
        {
            int x = 0;
            int[] arr = new int[5];
            arr[0] = 1234;
            arr[1] = 432;
            arr[2] = 4325;
            arr[3] = 13454;
            Console.WriteLine("排序前");
            Console.WriteLine("");
            for (int i = 0; i < arr.Length; i++)
            {
                if (i != 4)
                {
                    Console.Write(arr[i] + " .");
                }
            }
            Console.WriteLine("");
            Console.WriteLine("请输入要插入的数字：");
            string a = Console.ReadLine();
            x = int.Parse(a);
            arr[4] = x;
            for (int j = 0; j < 10; j++)
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    if (i < 4)
                    {
                        if (arr[i] < arr[i + 1])
                        {
                            (arr[i], arr[i + 1]) = (arr[i + 1], arr[i]);
                        }
                    }
                }
            }

            Console.WriteLine("");
            Console.WriteLine("排序后");
            Console.WriteLine("");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " .");
            }
        }


    }
}
